/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Graficos;

/**
 *
 * @author danilo
 */
   import java.awt.Color;
   import javax.swing.JPanel;
   import org.jfree.chart.ChartFactory;
   import org.jfree.chart.ChartPanel;
   import org.jfree.chart.JFreeChart;
   import org.jfree.chart.axis.NumberAxis;
   import org.jfree.chart.plot.PlotOrientation;
   import org.jfree.chart.plot.XYPlot;
   import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
   import org.jfree.data.function.Function2D;
   import org.jfree.data.general.DatasetUtilities;
   import org.jfree.data.xy.XYDataset;
   import org.jfree.ui.ApplicationFrame;
   import org.jfree.ui.RectangleInsets;
/**
 *
 * @author danilo
 */
public class graficoLinha extends ApplicationFrame {


      public graficoLinha(String title) {
         super(title);
         JPanel chartPanel = createDemoPanel();
         chartPanel.setPreferredSize(new java.awt.Dimension(800, 400));
         setContentPane(chartPanel);
      }

      public static XYDataset createDataset1() {
         Function2D f1 = new Function2D() {
            public double getValue(double x) {
            return x;
            }
         };
         return DatasetUtilities.sampleFunction2D(f1,1950.0, 2010.0, 100,"f1");
      }

     /* private static XYDataset createDataset2() {
         Function2D f2 = new Function2D() {
            public double getValue(double x) {
            return 50 - 50 * x * x;
            }
         };
         return DatasetUtilities.sampleFunction2D(f2, -2.0, 2.0, 300, "f2");
      }*/

      private static JFreeChart createChart(XYDataset dataset1) {
         // create the chart...
         JFreeChart chart = ChartFactory.createXYLineChart(
            "Vacinas",      // chart title
            "Anos",         // x axis label
            "Quantidade",   // y axis label
            dataset1,                  // data
            PlotOrientation.VERTICAL,
            false,                     // include legend
            true,                     // tooltips
            false                     // urls
         );

         // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
         chart.setBackgroundPaint(Color.white);

         // get a reference to the plot for further customisation...
         XYPlot plot = (XYPlot) chart.getPlot();
         plot.setDataset(1, dataset1);
         plot.setBackgroundPaint(Color.lightGray);
         plot.setAxisOffset(new RectangleInsets(10.0, 10.0, 10.0, 10.0));
         plot.setDomainGridlinePaint(Color.white);
         plot.setRangeGridlinePaint(Color.white);

         XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
         renderer.setShapesVisible(false);

         XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(true, false);
         plot.setRenderer(1, renderer2);

         // change the auto tick unit selection to integer units only...
         NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
         rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
         // OPTIONAL CUSTOMISATION COMPLETED.

         return chart;
      }

      public static JPanel createDemoPanel() {
         JFreeChart chart = createChart(createDataset1());
         return new ChartPanel(chart);
      }

   }
